<?php

namespace common\models\auth;

use Yii;
use common\models\BaseModels;

/**
 * This is the model class for table "user_admin_company".
 *
 * @property integer $id
 * @property integer $groupId
 * @property string $comcode
 * @property string $name
 * @property string $corporation
 * @property string $type
 * @property string $shareHolder
 * @property string $registCapital
 * @property string $paidInCapital
 * @property string $registAddress
 * @property string $openingTime
 * @property string $verifyTime
 * @property string $registAuthority
 * @property string $registCode
 * @property string $groupCode
 * @property string $taxCode
 * @property string $phone400
 * @property string $address
 * @property string $telphone
 * @property string $faxNumber
 * @property string $mailNumber
 * @property string $remark
 * @property integer $is_valid
 * @property integer $created_at
 * @property integer $updated_at
 */
class UserAdminCompany extends BaseModels
{

    /**
     * 获取当前公司的集团名称
     */
    public function getTopGroupName($group_id){
        return UserAdminGroup::getGroupName($group_id);
    }

    /**
     * 获取可选的公司名称
     */
    public static function getTopCompanyList(){
        $condition = "is_valid=1";
        $topArray  = []; 
        $topDept   = static::find()->where($condition)->select(['id','name'])->orderBy('id desc')->limit(20)->asArray()->all();
        foreach ($topDept as $item) {
            $topArray[$item["id"]] = $item["name"];
        }
        
        return $topArray;
    }


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'user_admin_company';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['groupId', 'is_valid', 'created_at', 'updated_at'], 'integer'],
            [['comcode', 'created_at', 'updated_at'], 'required'],
            [['comcode', 'corporation', 'type', 'openingTime', 'verifyTime', 'phone400', 'telphone', 'faxNumber'], 'string', 'max' => 16],
            [['name', 'registAuthority', 'address'], 'string', 'max' => 64],
            [['shareHolder'], 'string', 'max' => 512],
            [['registCapital', 'paidInCapital', 'registCode', 'groupCode', 'taxCode', 'mailNumber'], 'string', 'max' => 32],
            [['registAddress'], 'string', 'max' => 128],
            [['remark'], 'string', 'max' => 256],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id'      => Yii::t('app_table', 'ID'),
            'groupId' => Yii::t('app_table', 'admin company groupId'),
            'comcode' => Yii::t('app_table', 'admin company comcode'),
            'name'    => Yii::t('app_table', 'admin company name'),
            'corporation' => Yii::t('app_table', 'admin company corporation'),
            'type'        => Yii::t('app_table', 'admin company type'),
            'shareHolder' => Yii::t('app_table', 'admin company shareHolder'),
            'registCapital' => Yii::t('app_table', 'admin company registCapital'),
            'paidInCapital' => Yii::t('app_table', 'admin company paidInCapital'),
            'registAddress' => Yii::t('app_table', 'admin company registAddress'),
            'openingTime'   => Yii::t('app_table', 'admin company openingTime'),
            'verifyTime'    => Yii::t('app_table', 'admin company verifyTime'),
            'registAuthority' => Yii::t('app_table', 'admin company registAuthority'),
            'registCode' => Yii::t('app_table', 'admin company registCode'),
            'groupCode'  => Yii::t('app_table', 'admin company groupCode'),
            'taxCode'    => Yii::t('app_table', 'admin company taxCode'),
            'phone400'   => Yii::t('app_table', 'admin company phone400'),
            'address'    => Yii::t('app_table', 'admin company address'),
            'telphone'   => Yii::t('app_table', 'admin company telphone'),
            'faxNumber'  => Yii::t('app_table', 'admin company faxNumber'),
            'mailNumber' => Yii::t('app_table', 'admin company mailNumber'),
            'remark'     => Yii::t('app_table', 'remark'),
            'is_valid'   => Yii::t('app_table', 'isvalid'),
            'created_at' => Yii::t('app_table', 'created_at'),
            'updated_at' => Yii::t('app_table', 'updated_at'),
        ];
    }
}
